﻿using MediatR;
using RedDragon.Common.Domain.Manufacture;
using RedDragon.Common.Domain.Process;
using RedDragon.Common.Domain.warehouse;
using RedDragon.Common.Infrastructure.Interface;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.ProcessW
{
    public class ProcessCreateHandler : IRequestHandler<ProcessCreateCommon, Result>
    {
        public readonly IBaseRepository<Process> ProcessRepository;

        public ProcessCreateHandler(IBaseRepository<Process> processRepository)
        {
            ProcessRepository = processRepository;
        }

        public async Task<Result> Handle(ProcessCreateCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = 0, Msg = "工艺新增失败" };
            try
            {
                var res = new Process()
                {
                    ProcessNumber = request.ProcessNumber,
                    ProcessName = request.ProcessName,
                    WorkCentreCode = request.WorkCentreCode,
                    ProcessCreateTime = DateTime.Now,
                    ProcessCreateName = "",
                    ProcessState = true,
                    ProcessAudit = 0,
                };
                var res1 = await ProcessRepository.Add(res);
                if (res1 != 0)
                {
                    result.Code = 1;
                    result.Msg = "工艺新增成功";
                }



            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
